package application;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import universe.BlockHandler;
import universe.Game;


public class KeyTetris implements KeyListener {		

	private Tetris theTetris;
	//private Game theGame;

	public KeyTetris(Tetris pTetris){
		theTetris = pTetris;
		//System.out.println("constructor keylistener");
	}

	public void keyPressed(KeyEvent e){
		//ACTIONS CLAVIER PENDANT UNE PARTIE
		if(theTetris.getGame() != null ){		
			if(e.getKeyCode() == Utils.keyMoveLeft || e.getKeyCode() == Utils.keyMoveLeft2){
				//System.out.println("gauche");
				theTetris.getGame().moveLeft();
			}
			else if(e.getKeyCode() == Utils.keyMoveRight || e.getKeyCode() == Utils.keyMoveRight2){
				//System.out.println("droite");
				theTetris.getGame().moveRight();
			}
			else if(e.getKeyCode() == Utils.keyMoveDown || e.getKeyCode() == Utils.keyMoveDown2){
				//System.out.println("bas");
				theTetris.getGame().moveDown();
				if(!display.Utils.DISPLAY_CLONE) universe.Utils.bonus += 1;
			}
			else if(e.getKeyCode() == Utils.keyRotate || e.getKeyCode() == Utils.keyRotate2){
				//System.out.println("haut");
				theTetris.getGame().rotate();
			}
			else if(e.getKeyCode() == KeyEvent.VK_C){
				theTetris.getTetrisMenuBar().windowConfigurer(TetrisMenuBar.CONFIG);
			}
			else if(e.getKeyCode() == KeyEvent.VK_N){
				//System.out.println("Nouvelle Partie");
				theTetris.newGame();
			}
			else if(e.getKeyCode() == KeyEvent.VK_S){
				theTetris.showScorePanel();
			}
			else if(e.getKeyCode() == Utils.keyPause || e.getKeyCode() == Utils.keyPause2){
				//System.out.println("PAAAAAUUUUSSSEEEEE");
				theTetris.togglePause();
			}
			else if(e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_Q || e.getKeyCode() == KeyEvent.VK_ESCAPE){
				//System.out.println("EXIT");
				theTetris.showHomeMenu();
			}
			else if(e.getKeyCode() == Utils.keyDropDown || e.getKeyCode() == Utils.keyDropDown2){
				//System.out.println("ENTER");
				theTetris.getGame().dropDown();
				
				if(!display.Utils.DISPLAY_CLONE) 
					universe.Utils.addBonus();
			}
		}
		else{
			//System.out.println("Il n'y a pas de game en cours");
			if(e.getKeyCode() == KeyEvent.VK_C){
				theTetris.getTetrisMenuBar().windowConfigurer(1);
			}
			else if(e.getKeyCode() == KeyEvent.VK_S){
				theTetris.showScorePanel();
			}
			else if(e.getKeyCode() == KeyEvent.VK_N){
				theTetris.newGame();
			}
			else if(e.getKeyCode() == KeyEvent.VK_Q || e.getKeyCode() == KeyEvent.VK_ESCAPE){
				//System.out.println("EXIT");
				System.exit(0);
			}
			if(e.getKeyCode() == KeyEvent.VK_HOME){
				theTetris.showHomeMenu();
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub

	}



}
